package com.crm.system.controller.productManager;

import com.alibaba.fastjson.JSONObject;
import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.entity.productManager.CustomerMemberProductCourse;
import com.crm.model.vo.productManager.CustomerMemberProductCourseVO;
import com.crm.model.vo.productManager.CustomerProductVO;
import com.crm.system.service.productManager.CustomerMemberProductCourseService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会员产品课程
 * @author luojie
 * @date 2021/5/11 16:23
 */
@Slf4j
@RestController
@RequestMapping("/customerMemberProductCourse")
public class CustomerMemberProductCourseController {

    @Autowired
    private CustomerMemberProductCourseService memberProductCourseService;

    /***
     * @Description:查询未添加的会员产品课程列表
     * @Author: luojie
     * @Date: 2021/5/12 15:14
     */
    @PostMapping("/selectNotAddCustomerMemberProductCourse")
    public DataResponse selectNotAddCustomerMemberProductCourse(@RequestBody JSONObject body){
        //产品名称
        String productName = body.getString("productName");
        //服务项关系表主键
        String memberProductRelationId = body.getString("memberProductRelationId");
        //页码
        Integer pageIndex = body.getInteger("pageIndex");
        //每页显示个数
        Integer pageSize = body.getInteger("pageSize");
        DhPageInfo<CustomerProductVO> customerProductVOList = memberProductCourseService.selectNotAddCustomerMemberProductCourse(productName, memberProductRelationId,pageIndex,pageSize);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),customerProductVOList);
    }
    /***
     * @Description:添加会员产品课程
     * @Param: body 入参对象
     * @Author: luojie
     * @Date: 2021/5/12 9:48
     */
    @PostMapping("/addCustomerMemberProductCourse")
    public DataResponse addCustomerMemberProductCourse(@RequestBody JSONObject body){
        //会员产品课程列表
        List<CustomerMemberProductCourse> memberProductCourseList = body.getJSONArray("memberProductCourse").toJavaList(CustomerMemberProductCourse.class);
        //会员产品-服务项关系id
        String memberProductRelationId = body.getString("memberProductRelationId");
        Boolean result = memberProductCourseService.addCustomerMemberProductCourse(memberProductCourseList,memberProductRelationId);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }

    /***
     * @Description:根据会员产品服务项id查询会员产品课程
     * @Param: memberProductRelationId 会员产品服务项id
     * @Author: luojie
     * @Date: 2021/5/12 9:54
     */
    @GetMapping("/selectMemberProductCourseByRelationId")
    public DataResponse selectMemberProductCourseByRelationId(@RequestParam String memberProductRelationId){
        //会员产品课程列表
        List<CustomerMemberProductCourseVO> courseVOS = memberProductCourseService.selectMemberProductCourseByRelationId(memberProductRelationId);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),courseVOS);
    }

    /***
     * @Description:根据会员产品服务项id查询会员产品课程
     * @Param: memberProductRelationId 会员产品服务项id
     * @Author: luojie
     * @Date: 2021/5/12 9:54
     */
    @GetMapping("/delMemberProductCourseByCourseId")
    public DataResponse delMemberProductCourseByCourseId(@RequestParam String memberProductCourseId){
        Boolean result = memberProductCourseService.delMemberProductCourseByCourseId(memberProductCourseId);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }
}
